<style type="text/css">

a.postpro
{
	color: #005F95;
    font-family: Arial;
    font-size: 12px;
    text-decoration: none;
	font-weight:bold;
}


</style>

<?php
$sql = "SELECT a.id,a.`category`, a.`stored_image_name`,count(b.id) tot_count FROM ".$base_obj->CLASSIFIEDS_CAT." a
		INNER JOIN ".$base_obj->CLASSIFIEDS_ADS." b ON (a.id=b.category AND b.Status = '1')
		WHERE active_status = '1' GROUP BY a.id";
$res = $base_obj->exec_query($sql);
$data = $base_obj->fetch_row_all($res);

$share_count = floor(count($data)/3);
$rem = count($data)%3;
$fst_col = $share_count;
$fst_start = 1;
$sec_start = $fst_start+$share_count;
$third_start = $sec_start+$share_count;

if($rem > 0) {
	$sec_start++;
	$third_start++;
	
	if($rem > 1) {
		$third_start++;
	}
}
/*echo "<br/>1 - ".$fst_start;
echo "<br/>2 * ".$sec_start;
echo "<br/>3 = ".$third_start;*/
?>
<div class="contentwarp">
      <!-- Begin contentwarpLeft -->
      <!-- End contentwarpLeft -->
      <!-- Begin contentwarpMiddle -->
      <div class="contentwarpMiddle">
        <div class="clearfix" id="the-content" style="width:970px;">
        <div style="height:20px; float:right;">
        <a href="index.php?page=classifieds&view=post_classifieds_ads" class="postpro">Click Here To Post your Products</a>
        </div>
          <div id="home">
            <!-- C 1 -->
            <?php
			for($i=0;$i<count($data);$i++) {
				if(($i+1) == $fst_start) {
					
					echo '<div class="column" id="'.($i+1).'">';
				}
				
				if(($i+1) == $sec_start) {
					
					echo '<div class="column" id="'.($i+1).'">';
				}
				
				if(($i+1) == $third_start) {
					echo '<div class="column last" id="'.($i+1).'">';
				}
			
			?>
              
              <div class="block">
              
                <div class="guy"><img width="30" alt="" src="images/sale.jpg"></div>
                <h3 class="cbb" style="font-size:12px;"> <strong><?php echo $data[$i]['category']?></strong> <small style="float:right; font-size:11px; color:#666;">(<?php echo number_format($data[$i]['tot_count'],0,0,3); ?>)</small></h3>
                <?php
				$sql = "SELECT b.id,b.`sub_cat_name` FROM ".$base_obj->CLASSIFIEDS_SUB_CAT." b 
						INNER JOIN ".$base_obj->CLASSIFIEDS_ADS." c ON (b.id=c.sub_category AND c.Status = '1')
						WHERE b.active_status = '1' AND b.category_id = '".$data[$i]['id']."' GROUP BY b.id";
				$res = $base_obj->exec_query($sql);
				$data_in = $base_obj->fetch_row_all($res);
				?>
                <ul>
                <?php
				for($j=0;$j<count($data_in);$j++) {
				?>
                  <li><a href="index.php?page=classifieds&view=cat&cat_id=<?php echo $data_in[$j]['id'];?>"><?php echo $data_in[$j]['sub_cat_name'];?></a></li>
                  <?php } ?>
                </ul>
              </div>
              <?php 
			  if(($i+1) == ($sec_start-1)) {
					echo '</div> <!--First end-->';
			  }
			  if(($i+1) == ($third_start-1)) {
					echo '</div> <!--second end-->';
			  }
			  if($i == (count($data)-1)) {
				  echo '</div> <!--Third end-->';
			  }
			  ?>
            <?php }  ?>
          </div>
        </div>
      </div>
      <!-- End contentwarpMiddle -->
      <div class="contentwarpRight">
      <?php include("includes/right_content.php");?>
      </div>
      <!-- End contentwarp -->
    </div>